package com.hqyj.project.controller;

import com.hqyj.project.entity.User;
import com.hqyj.project.service.UserService;
import com.hqyj.project.utils.CommonResult;
import com.hqyj.project.vo.EmailVo;
import com.hqyj.project.vo.PageUserVo;
import com.hqyj.project.vo.UserAllVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public CommonResult login(@RequestBody User user){
        return userService.login(user.getUserName(),user.getUserPwd());
    }

    @GetMapping("/logout")
    public CommonResult logout(){
        return userService.logout();
    }

    /**
    *@ClassNname:
    *@Description:    邮箱验证修改密码，发送验证码
    *@Author wzk
    *@Date 2023/9/14
    *@Version 1.0
    */
    @PostMapping("/emailCode")
    public CommonResult emailCode(@RequestBody UserAllVo userAllVo){
        return userService.emailCode(userAllVo.getUserName(),userAllVo.getUserEmail());
    }

    /**
    *@ClassNname:
    *@Description:邮箱验证修改密码
    *@Author wzk
    *@Date 2023/9/15
    *@Version 1.0
    */
    @PostMapping("/updateUserPwd")
    public CommonResult updateUserPwd(@RequestBody EmailVo emailvo){
        return userService.updateUserPwd(emailvo);
    }



    /**
    *@ClassNname:
    *@Description: 用于查询用户权限菜单
    *@Author wzk
    *@Date 2023/9/11
    *@Version 1.0
    */
    @GetMapping("/menuList/{userName}")
    public CommonResult menuList(@PathVariable String userName){
        return userService.selectUserMenuList(userName);
    }


    /**
     *@ClassNname:
     *@Description:  登录档当前用户的个人信息
     *@Author wzk
     *@Date 2023/9/14
     *@Version 1.0
     */
    @PostMapping("/selectLoginUser/{userName}")
    public CommonResult selectLoginUser(@PathVariable("userName") String userName){
        return userService.selectLoginUser(userName);
    }

    /**
    *@ClassNname:
    *@Description:  登录用户修改个人信息
    *@Author wzk
    *@Date 2023/9/14
    *@Version 1.0
    */
    @PostMapping("/updateLoginUser")
    public CommonResult updateLoginUser(@RequestBody UserAllVo userAllVo){
        return userService.updateLoginUser(userAllVo);
    }


    /**
    *@ClassNname:
    *@Description: 查询所有员工信息
    *@Author wzk
    *@Date 2023/9/12
    *@Version 1.0
    */
    @GetMapping("/selectUserAll")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult selectUserAll(PageUserVo page){
        return userService.selectUserAll(page);
    }

    /**
    *@ClassNname:
    *@Description:删除用户
    *@Author wzk
    *@Date 2023/9/12
    *@Version 1.0
    */
    @PutMapping("/deleteUser/{userId}")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult deleteUser(@PathVariable("userId") Integer userId){
        return userService.deleteUser(userId);
    }

    /**
    *@ClassNname:
    *@Description: 通过姓名和电话进行模糊查询
    *@Author wzk
    *@Date 2023/9/13
    *@Version 1.0
    */
    @GetMapping("/selectLickUser")
    public CommonResult selectLickUser(String userRealName,String userTel){
        return userService.selectLickUser(userRealName,userTel);
    }

    /**
    *@ClassNname:
    *@Description:修改用户信息
    *@Author wzk
    *@Date 2023/9/13
    *@Version 1.0
    */
    @PostMapping("/updateUser")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult updateUser(@RequestBody UserAllVo userAllVo){
        return userService.updateUser(userAllVo);
    }


    /**
    *@ClassNname:
    *@Description:   插入用户 ，输入用户信息
    *@Author wzk
    *@Date 2023/9/14
    *@Version 1.0
    */
    @PostMapping("/insertUser")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult insertUser(@RequestBody UserAllVo userAllVo){
        return userService.insertUser(userAllVo);
    }

    /**
    *@ClassNname:
    *@Description: 查询用户账号是否存在
    *@Author wzk
    *@Date 2023/9/15
    *@Version 1.0
    */
    @GetMapping("/duplicateUserName/{userName}")
    public CommonResult duplicateUserName(@PathVariable("userName")String userName){
        return userService.duplicateUserName(userName);
    }

}
